﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace IAC_2013.com.iac.util
{
    class ValidateUtils
    {
        /*
         * Ham kiem tra so nhap vao la kieu so
         */

        public static String checkNum(String word)
        {
            String result = "";
            for (int i = 0; i < word.Length; i++)
            {
                if (word[i].ToString().Trim().Equals("0"))
                {
                    result += word[i].ToString();
                }
                if (word[i].ToString().Trim().Equals("1"))
                {
                    result += word[i].ToString();
                }
                if (word[i].ToString().Trim().Equals("2"))
                {
                    result += word[i].ToString();
                }
                if (word[i].ToString().Trim().Equals("3"))
                {
                    result += word[i].ToString();
                }
                if (word[i].ToString().Trim().Equals("4"))
                {
                    result += word[i].ToString();
                }
                if (word[i].ToString().Trim().Equals("5"))
                {
                    result += word[i].ToString();
                }
                if (word[i].ToString().Trim().Equals("6"))
                {
                    result += word[i].ToString();
                }
                if (word[i].ToString().Trim().Equals("7"))
                {
                    result += word[i].ToString();
                }
                if (word[i].ToString().Trim().Equals("8"))
                {
                    result += word[i].ToString();
                }
                if (word[i].ToString().Trim().Equals("9"))
                {
                    result += word[i].ToString();
                }
            }
            return result;
        }

        public Boolean checkNumber(String _number)
        {
            for (int i = 0; i < _number.Length; i++)
            {
                int count = 0;
                if (!(_number[i].ToString().Trim().Equals("0")))
                {
                    count++;
                }
                if (!(_number[i].ToString().Trim().Equals("1")))
                {
                    count++;
                }
                if (!(_number[i].ToString().Trim().Equals("2")))
                {
                    count++;
                }
                if (!(_number[i].ToString().Trim().Equals("3")))
                {
                    count++;
                }
                if (!(_number[i].ToString().Trim().Equals("4")))
                {
                    count++;
                }
                if (!(_number[i].ToString().Trim().Equals("5")))
                {
                    count++;
                }
                if (!(_number[i].ToString().Trim().Equals("6")))
                {
                    count++;
                }
                if (!(_number[i].ToString().Trim().Equals("7")))
                {
                    count++;
                }
                if (!(_number[i].ToString().Trim().Equals("8")))
                {
                    count++;
                }
                if (!(_number[i].ToString().Trim().Equals("9")))
                {
                    count++;
                }
                if (count > 9)
                {
                    return false;
                }
            }
            return true;
        }

        /*
         * ham kiem tra dinh dang email nhap vao
         */
        public Boolean checkEmail(String _email)
        {
            String key1 = "abcdefghijknmlopqrstuvxyzw0123456789";
            String key2 = "ABCDEFGHIJKNMLOPQRSTUVXYZW0123456789";

            for (int i = 0; i < 36; i++)
            {
                if (_email.StartsWith(key1[i].ToString()) || _email.StartsWith(key2[i].ToString()))
                {
                    for (int j = 0; j < _email.Length; j++)
                    {
                        if (_email[j].ToString().Trim().Equals("@"))
                        {
                            for (int k = 0; k < 36; k++)
                            {
                                if (_email[j + 1].ToString().StartsWith(key1[k].ToString()) || 
                                    _email[j + 1].ToString().StartsWith(key2[k].ToString()))
                                {
                                    for (int n = 0; n < 36; n++)
                                    {
                                        for (int l = _email[j]; l < _email.Length; l++)
                                        {
                                            if (_email[l].ToString().Trim().Equals("."))
                                            {
                                                for (int h = 0; h < 36; h++)
                                                {
                                                    if (_email.EndsWith(key1[h].ToString()) || _email.EndsWith(key2[h].ToString()))
                                                    {
                                                        return true;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return false;
        }

    }
}
